<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ include file="../include/admincontent.jsp" %>
<div id="Content">
    <form id="modelform" method="post" action="/BaseExaminer/EditAction">
        <input type="hidden" name="id" value="${group.id}" datatype="*" nullmsg="非法访问"/>
<%--        <div class="btnbar">
            <button type="submit" class="save">保存</button>
        </div>--%>
        <div class="toolbars">
            <a id="save">
                <em class="ico16 save_traft_16"></em>
                <span class="menu_span" title="保存">保存</span>
            </a>
            <a id="add">
                <em class="ico16 add_new"></em>
                <span class="menu_span" title="添加">添加</span>
            </a>
        </div>
        <table class="treeTable inputform" style="margin-top: 10px">
            <thead>
            <tr>
                <td colspan="2">考官分组信息</td>
            </tr>
            </thead>
            <tbody>
            <tr>
                <td width="120">分组名称:</td>
                <td>
                    <div><input type="text" name="name" value="${group.name}" datatype="*" nullmsg="分组名称不能为空！" style="line-height: 38px;height: 38px;padding: 0 5px;width: calc(100% - 5px);border: 0;"/></div>
                </td>
            </tr>
            </tbody>
        </table>
        <table class="treeTable inputform" style="margin-top:5px;" id="gusertb">
            <thead>
            <tr>
                <td colspan="6">考官组员信息</td>
            </tr>
            <tr>
                <td>考官编号</td>
                <td>考官姓名</td>
                <td>考官电话</td>
                <td>评分权重(分数/百分数)</td>
                <td width="80">主考官</td>
                <td class="tdwidth"></td>
<%--                <td width="30">
                    <div>
                        <button type="button" class="add"></button>
                    </div>
                </td>--%>
            </tr>
            </thead>
            <tbody id="result">
            <c:forEach var="examiner" items="${examiners}" varStatus="item">
                <tr>
                    <td>${examiner.code}<input type="hidden" name="examiners[${item.index}].code"
                                               value="${examiner.code}" datatype="*" nullmsg="考官编号不能为空"/></td>
                    <td>${examiner.uname}<input type="hidden" name="examiners[${item.index}].uname"
                                                value="${examiner.uname}" datatype="*" nullmsg="考官姓名不能为空"/></td>
                    <td>
                        <div><input type="text" name="examiners[${item.index}].tel" value="${examiner.tel}" datatype="*"
                                    nullmsg="考官电话不能为空"/></div>
                    </td>
                    <td>
                        <div><input type="text" name="examiners[${item.index}].uweight" value="${examiner.uweight}"
                                    datatype="*" nullmsg="评分权重不能为空"/></div>
                    </td>
                    <td>
                        <div>
                            <select name="examiners[${item.index}].role">
                                <option value="否">否</option>
                                <option value="是">是</option>
                            </select>
                            <input type="hidden" value="${examiner.role}"/>
                        </div>
                    </td>
                        <%-- <td>
%--                        <div>
                                <button type="button" class="del"></button>
                            </div>
                        </td>--%>
                    <td class="tdwidth">
                        <button type="button"  class="layui-btn layui-btn-sm layui-btn-normal del"><i class="layui-icon"></i>删除</button>
                    </td>
                </tr>
            </c:forEach>
            </tbody>
        </table>
    </form>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        //添加成员
/*        $(document).delegate('#gusertb .add', 'click', function () {
            openLayer('选择人员', '/BaseExaminer/selectuser', '1500px', '90%');
        });*/
        $(document).delegate('#add','click',function () {
            openLayer('选择人员', '/BaseExaminer/selectuser', '90%', '90%');
        });
        //删除成员
        $(document).delegate('#gusertb .del', 'click', function () {
            $(this).parent().parent().remove();
            setItemNum();
        });
        $("select").each(function () {
            $(this).val($(this).next().val());
        });

        $('#save').click(function () {
            var rows = gusertb.rows.length;
            var data = {};
            data["id"] = $("input[name = 'id']").val();
            data["name"] = $("input[name = 'name']").val();
            for (var i = 0; i < rows - 2; i++) {
                var exCode = $("input[name='examiners[" + i + "].code']").val()
                var exCodeName = "examiners[" + i + "].code";
                data[exCodeName] = exCode;

                var exUname = $("input[name='examiners[" + i + "].uname']").val();
                var exUnameName = "examiners[" + i + "].uname";
                data[exUnameName] = exUname;

                var exTel = $("input[name='examiners[" + i + "].tel']").val();
                var exTelName = "examiners[" + i + "].tel";
                data[exTelName] = exTel;

                var exWeight = $("input[name='examiners[" + i + "].uweight']").val();
                var exWeightName = "examiners[" + i + "].uweight";
                data[exWeightName] = exWeight;

                var exRole = $("select[name='examiners[" + i + "].role']").val();
                var exRoleName = "examiners[" + i + "].role";
                data[exRoleName] = exRole;

            }

            $.ajax({
                url: "/BaseExaminer/EditAction",
                type: 'POST',
                data: data,
                success: function (data) {
                    if (data.state){
                        layer.msg(data.Message, {icon: 1});
                        parent.location.reload();
                    }else {
                        layer.msg(data.Message, {icon: 2});
                    }
                },
                error: function (data) {
                    layer.msg(data.Message, {icon: 2});
                }
            });

        });
    });

    function setItemNum() {
        $('#gusertb tbody tr').each(function (_index) {
            $(this).find('td:eq(0) input').attr('name', 'examiners[' + _index + '].code');
            $(this).find('td:eq(1) input').attr('name', 'examiners[' + _index + '].uname');
            $(this).find('td:eq(2) input').attr('name', 'examiners[' + _index + '].tel');
            $(this).find('td:eq(3) input').attr('name', 'examiners[' + _index + '].uweight');
            $(this).find('td:eq(4) select').attr('name', 'examiners[' + _index + '].role');
        });
    }
</script>
</body>
</html>